While we guarantee that the widget that a controller
is attached to stays around while it is handling an event,
the same is not true for the root that the widget belongs
to. In corner cases (such as clicking "Close" in the
fallback window menu), it may already be gone.
Avoid a critical in that case.
Fixes: #2998
focus_out (GtkEventController *controller,
GtkPopoverMenu *menu)
{
- GtkWidget *new_focus = gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (menu)));
+ GtkRoot *root;
+ GtkWidget *new_focus;
+
+ root = gtk_widget_get_root (GTK_WIDGET (menu));
+ if (!root)
+ return;
+
+ new_focus = gtk_root_get_focus (root);
if (!gtk_event_controller_focus_contains_focus (GTK_EVENT_CONTROLLER_FOCUS (controller)) &&
new_focus != NULL)